Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove NodeId from Block and Expr #58698

Closed
wants to merge 12 commits into from

Conversation

ljedrz
Copy link
Contributor

@ljedrz ljedrz commented Feb 24, 2019

The next iteration of #57578. The relevant part is the last 2 commits (the others are dependencies).

Removes NodeId from

  • hir::Block
  • hir::Expr

Blocked by #58561, can be appended to it.

r? @Zoxc

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 24, 2019
@ljedrz ljedrz changed the title HirIdify more nodes Remove NodeId from Block and Expr Feb 24, 2019
@ljedrz
Copy link
Contributor Author

ljedrz commented Feb 24, 2019

Oof, I forgot about the Expr size assertion; I'll update shortly.

@@ -679,7 +678,7 @@ pub fn check_unsafety<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) {
}

let mut unsafe_blocks: Vec<_> = unsafe_blocks.into_iter().collect();
unsafe_blocks.sort();
unsafe_blocks.sort_by_cached_key(|(hir_id, _)| tcx.hir().hir_to_node_id(*hir_id));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's find to just use sort here. Do you know which errors changed order with that?

Copy link
Contributor Author

@ljedrz ljedrz Feb 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, plain sort breaks 2 issue test cases related to unused unsafe (unfortunately I forgot to register which ones).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well we can land sort_by_cached_key here and you could open a new PR with an additional commit which changes it back to sort, so we can look at the failures.

@@ -425,8 +425,8 @@ impl<'hir> pprust_hir::PpAnn for IdentifiedAnnotation<'hir> {
}
pprust_hir::AnnNode::Expr(expr) => {
s.s.space()?;
s.synth_comment(format!("node_id: {} hir local_id: {}",
expr.id, expr.hir_id.local_id.as_u32()))?;
s.synth_comment(format!("expr hir_id: {} hir local_id: {}",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You added expr here. Not sure if that's good or bad =P

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, so that it matches the other branches; I mean, it shouldn't break anything ^^.

@@ -271,7 +271,8 @@ fn def_id_visibility<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId)
return (ctor_vis, span, descr);
}
Node::Expr(expr) => {
return (ty::Visibility::Restricted(tcx.hir().get_module_parent(expr.id)),
return (ty::Visibility::Restricted(
tcx.hir().get_module_parent_by_hir_id(expr.hir_id)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This formatting doesn't quite make sense to me =P

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I was just trying to squeeze it so that tidy doesn't complain; I can adjust it if need be :P.

@Zoxc
Copy link
Contributor

Zoxc commented Feb 24, 2019

I've looked over this and it looks good. You can append it to #58561

@ljedrz
Copy link
Contributor Author

ljedrz commented Feb 24, 2019

@Zoxc done; what about that static_assert on Expr, though? I forgot to alter it, but it doesn't seem to break anything.

@ljedrz
Copy link
Contributor Author

ljedrz commented Feb 24, 2019

Oh, and closing in favor of #58561.

@ljedrz ljedrz closed this Feb 24, 2019
@Zoxc
Copy link
Contributor

Zoxc commented Feb 24, 2019

@ljedrz That's probably due to padding.

@ljedrz
Copy link
Contributor Author

ljedrz commented Feb 24, 2019

@Zoxc I ran tests with that plain sort locally; the results are as follows:

failures:

---- [ui] ui\issues\issue-45107-unnecessary-unsafe-in-closure.rs stdout ----
diff of stderr:

1       error: unnecessary `unsafe` block
-         --> $DIR/issue-45107-unnecessary-unsafe-in-closure.rs:7:13
+         --> $DIR/issue-45107-unnecessary-unsafe-in-closure.rs:9:38
3          |
4       LL |     unsafe {
5          |     ------ because it's nested under this `unsafe` block

-       LL |         let f = |v: &mut Vec<_>| {
-       LL |             unsafe { //~ ERROR unnecessary `unsafe`
-          |             ^^^^^^ unnecessary `unsafe` block
+       ...
+       LL |                 |w: &mut Vec<u32>| { unsafe { //~ ERROR unnecessary `unsafe`
+          |                                      ^^^^^^ unnecessary `unsafe` block
9          |
10      note: lint level defined here
11        --> $DIR/issue-45107-unnecessary-unsafe-in-closure.rs:1:8

14         |        ^^^^^^^^^^^^^
15
16      error: unnecessary `unsafe` block
-         --> $DIR/issue-45107-unnecessary-unsafe-in-closure.rs:9:38
+         --> $DIR/issue-45107-unnecessary-unsafe-in-closure.rs:7:13
18         |
19      LL |     unsafe {
20         |     ------ because it's nested under this `unsafe` block

-       ...
-       LL |                 |w: &mut Vec<u32>| { unsafe { //~ ERROR unnecessary `unsafe`
-          |                                      ^^^^^^ unnecessary `unsafe` block
+       LL |         let f = |v: &mut Vec<_>| {
+       LL |             unsafe { //~ ERROR unnecessary `unsafe`
+          |             ^^^^^^ unnecessary `unsafe` block
24
25      error: unnecessary `unsafe` block
26        --> $DIR/issue-45107-unnecessary-unsafe-in-closure.rs:13:34

---- [ui] ui\span\lint-unused-unsafe.rs stdout ----
diff of stderr:

47         |         ^^^^^^ unnecessary `unsafe` block
48
49      error: unnecessary `unsafe` block
-         --> $DIR/lint-unused-unsafe.rs:29:5
+         --> $DIR/lint-unused-unsafe.rs:30:9
51         |
52      LL | unsafe fn bad7() {
53         | ---------------- because it's nested under this `unsafe` fn

54      LL |     unsafe {                             //~ ERROR: unnecessary `unsafe` block
-          |     ^^^^^^ unnecessary `unsafe` block
+       LL |         unsafe {                         //~ ERROR: unnecessary `unsafe` block
+          |         ^^^^^^ unnecessary `unsafe` block
56
57      error: unnecessary `unsafe` block
-         --> $DIR/lint-unused-unsafe.rs:30:9
+         --> $DIR/lint-unused-unsafe.rs:29:5
59         |
60      LL | unsafe fn bad7() {
61         | ---------------- because it's nested under this `unsafe` fn

62      LL |     unsafe {                             //~ ERROR: unnecessary `unsafe` block
-       LL |         unsafe {                         //~ ERROR: unnecessary `unsafe` block
-          |         ^^^^^^ unnecessary `unsafe` block
+          |     ^^^^^^ unnecessary `unsafe` block
65
66      error: aborting due to 8 previous errors
67

failures:
    [ui] ui\issues\issue-45107-unnecessary-unsafe-in-closure.rs
    [ui] ui\span\lint-unused-unsafe.rs

@ljedrz ljedrz deleted the HirIdify_more_nodes branch February 26, 2019 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants